package com.hy.z.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hy.z.entity.User;
import com.hy.z.result.Result;
import com.hy.z.service.UserService;
import com.hy.z.vo.UserInfoVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Fhy
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户列表
     * 只有管理员才能查看所有用户列表
     * @return
     */
    @RequestMapping("/queryUserInfo")
    public Result queryUserInfo(long pageNum,long pageSize){
        IPage<UserInfoVo> listByPage = userService.getListByPage(pageNum, pageSize);
        return Result.success(listByPage);
    }

    @RequestMapping("/addUser")
    @RequiresPermissions(value = {"user:add"})
    public Result addUser(User user){
        boolean b = userService.addUser(user);
        if (b){//你没有操作权限
            return Result.success();
        }
        return Result.error();

    }

    @RequestMapping("/deleteUser")
    @RequiresPermissions(value = {"user:delete"})
    public Result deleteUser(Integer id){
        boolean b = userService.deleteUser(id);
        if (b){
            return Result.success();
        }
        return Result.error();
    }

}

